#ifndef __OPEN_PYTHON_MODULE__
#define __OPEN_PYTHON_MODULE__

#include <python2.6/Python.h>
#include <iostream>
#include <string>
using namespace std;

// print out the python object dictionary, 
// however, it is not used in this program
void printDict(PyObject* obj) {
	if (!PyDict_Check(obj))
		return;
	PyObject *k, *keys;
	keys = PyDict_Keys(obj);
	for (int i = 0; i < PyList_GET_SIZE(keys); i++) {
		k = PyList_GET_ITEM(keys, i);
		char* c_name = PyString_AsString(k);
		printf("%s\n", c_name);
	}
}

// open the file in python script with module_name
// return the status of the function
int openPyModule(const char *file_name) {
	Py_Initialize();
	if (!Py_IsInitialized())
		return -1;

	PyRun_SimpleString("import sys");   
	PyRun_SimpleString("sys.path.append('./')"); 

	// import module
	PyObject* pModule = PyImport_ImportModule(file_name);  
	if (!pModule) {
		printf("Cant open python file!\n");
		return -1;
	}

	// dict list of module
	PyObject* pDict = PyModule_GetDict(pModule);
	if(!pDict) {
		printf("Cant find dictionary.\n");
		return -1;
	}

    	Py_Finalize();  
	return 0;
}

#endif

